<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Cost_Edit extends Page
{
       public $Image1 = null;
       public $hfincident = null;
       public $btnAdd = null;
       public $edAmt = null;
       public $Label9 = null;
       public $edDesc = null;
       public $Label8 = null;
       function edAmtJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       //accept only numbers
       var numero = document.getElementById("edAmt").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edAmt").value = numero;
       <?php

       }

       function btnAddClick($sender, $params)
       {
       mysql_query("update incident_cost_tbl set
       description = '".$this->edDesc->Text."',
       amount = '".$this->edAmt->Text."'
       where auto_id ='".$this->hfincident->getValue()."'")or die("UPDATE INCIDENT - " . mysql_error());

       echo "<script language=javascript>
       alert('Updated record successfully!');
       window.opener.location.reload();
       window.close();
       </script>";

       }

       function Cost_EditCreate($sender, $params)
       {
       $incident_id = $_GET['auto_id'];
       $this->hfincident->setValue($incident_id);

       $query_cost = "select * from incident_cost_tbl where auto_id='".$this->hfincident->getValue()."'";
       $result_cost = mysql_query($query_cost)or die(mysql_error());
       $row_cost = mysql_fetch_array($result_cost);

       $this->edDesc->Text = $row_cost['description'];
       $this->edAmt->Text = $row_cost['amount'];

       }

}

global $application;

global $Cost_Edit;

//Creates the form
$Cost_Edit=new Cost_Edit($application);

//Read from resource file
$Cost_Edit->loadResource(__FILE__);

//Shows the form
$Cost_Edit->show();

?>